#pragma once
#pragma warning(disable:4996)       // disable checked iterator errors http://msdn.microsoft.com/en-us/library/aa985965(VS.80).aspx 

//
// Copyright (C) 2011 Steve Channell steve.channell@cepheis.com
//
// This file is part of Cephei.QL, an open-source library wrapper 
// arround QuantLib http://quantlib.org/
//
// Cephei.QL is open source software: you can redistribute it and/or modify it
// under the terms of the license.  You should have received a
// copy of the license along with this program; if not, please email
// <support@cepheis.com>. The license is also available online at
// <http://cepheis.com/license.htm>.
//
// This program is distributed in the hope that it will be useful, but WITHOUT
// ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS
// FOR A PARTICULAR PURPOSE.  See the license for more details.
//
// Version 2.101

#include <Macros.h>
#include <CoVector.h>
#include <CoMatrix.h>
#include <CoCube.h>
#include <ValueHelpers.h>
#include <Settings.h>

#include <gen/QL/Termstructures/Yield/RelativeDateRateHelper.h>
#pragma unmanaged 
#include <ql\termstructures\yield\ratehelpers.hpp>
#include <boost/smart_ptr/detail/spinlock.hpp>
#pragma managed 

using namespace System;
using namespace QuantLib;
using namespace Cephei;

using namespace Cephei::QL::Indexes;
using namespace Cephei::QL;
using namespace Cephei::QL::Times;
using namespace Cephei::QL::Termstructures;
using namespace Cephei::QL::Instruments;
#define HANDLE
#undef ABSTRACT
#undef STRUCT
namespace Cephei { namespace QL { namespace Termstructures { namespace Yield {
	//////////////////////////////////////////////////////////////////////////////////////////////
	// implementation of ISwapRateHelper
	public ref class CSwapRateHelper : 
            public CRelativeDateRateHelper,
            public Cephei::QL::Termstructures::Yield::ISwapRateHelper
	{
	protected: 
		boost::shared_ptr<QuantLib::SwapRateHelper>* _ppSwapRateHelper;
#ifdef HANDLE
		QuantLib::Handle<QuantLib::SwapRateHelper>* _phSwapRateHelper;
#endif
		Object^ _SwapRateHelperOwner;     // reference to object that manages the storage for this object
	internal:
		CSwapRateHelper (Double rate, Cephei::QL::Indexes::ISwapIndex^ swapIndex, Microsoft::FSharp::Core::FSharpOption<Cephei::QL::IQuote^>^ spread, Microsoft::FSharp::Core::FSharpOption<Cephei::QL::Times::IPeriod^>^ fwdStart, Microsoft::FSharp::Core::FSharpOption<Cephei::QL::Termstructures::IYieldTermStructure^>^ discountingCurve);
		CSwapRateHelper (Double rate, Cephei::QL::Times::IPeriod^ tenor, Cephei::QL::Times::ICalendar^ calendar, QL::Times::FrequencyEnum fixedFrequency, QL::Times::BusinessDayConventionEnum fixedConvention, Cephei::QL::Times::IDayCounter^ fixedDayCount, Cephei::QL::Indexes::IIborIndex^ iborIndex, Microsoft::FSharp::Core::FSharpOption<Cephei::QL::IQuote^>^ spread, Microsoft::FSharp::Core::FSharpOption<Cephei::QL::Times::IPeriod^>^ fwdStart, Microsoft::FSharp::Core::FSharpOption<Cephei::QL::Termstructures::IYieldTermStructure^>^ discountingCurve);
		CSwapRateHelper (Cephei::QL::IQuote^ rate, Cephei::QL::Times::IPeriod^ tenor, Cephei::QL::Times::ICalendar^ calendar, QL::Times::FrequencyEnum fixedFrequency, QL::Times::BusinessDayConventionEnum fixedConvention, Cephei::QL::Times::IDayCounter^ fixedDayCount, Cephei::QL::Indexes::IIborIndex^ iborIndex, Microsoft::FSharp::Core::FSharpOption<Cephei::QL::IQuote^>^ spread, Microsoft::FSharp::Core::FSharpOption<Cephei::QL::Times::IPeriod^>^ fwdStart, Microsoft::FSharp::Core::FSharpOption<Cephei::QL::Termstructures::IYieldTermStructure^>^ discountingCurve);
		CSwapRateHelper (Cephei::QL::IQuote^ rate, Cephei::QL::Indexes::ISwapIndex^ swapIndex, Microsoft::FSharp::Core::FSharpOption<Cephei::QL::IQuote^>^ spread, Microsoft::FSharp::Core::FSharpOption<Cephei::QL::Times::IPeriod^>^ fwdStart, Microsoft::FSharp::Core::FSharpOption<Cephei::QL::Termstructures::IYieldTermStructure^>^ discountingCurve);
        CSwapRateHelper (boost::shared_ptr<QuantLib::SwapRateHelper>& childNative, Object^ owner);
        CSwapRateHelper (QuantLib::SwapRateHelper& childNative, Object^ owner);
        CSwapRateHelper (CSwapRateHelper^ copy);
        CSwapRateHelper (System::Type^ t);
#ifdef STRUCT
        CSwapRateHelper (QuantLib::SwapRateHelper childNative);
#endif       
#ifdef HANDLE
		CSwapRateHelper (QuantLib::Handle<QuantLib::SwapRateHelper>& childNative, Object^ owner);
		CSwapRateHelper (QuantLib::Handle<QuantLib::SwapRateHelper> childNative);
#endif
		virtual ~CSwapRateHelper ();
		!CSwapRateHelper ();

	internal:
		QuantLib::SwapRateHelper& GetReference ();
		boost::shared_ptr<QuantLib::SwapRateHelper>& GetShared ();
		QuantLib::SwapRateHelper* GetPointer ();
        void SetSwapRateHelper (boost::shared_ptr<QuantLib::SwapRateHelper> native)
        {
            if (_ppSwapRateHelper != NULL)
                delete _ppSwapRateHelper;
            _ppSwapRateHelper = new boost::shared_ptr<QuantLib::SwapRateHelper> (native);
            SetRelativeDateRateHelper (boost::dynamic_pointer_cast<QuantLib::RelativeDateRateHelper> (*_ppSwapRateHelper));
        }
#ifdef HANDLE
		QuantLib::Handle<QuantLib::SwapRateHelper>& GetHandle ();
#endif
		virtual bool HasNative () override;
    public:
        property Cephei::QL::Times::IPeriod^ ForwardStart 
        {
		    virtual Cephei::QL::Times::IPeriod^ get () ;
        }
        property Double ImpliedQuote 
        {
		    virtual Double get () ;
        }
		virtual Cephei::QL::Termstructures::Yield::ISwapRateHelper^ SetTermStructure (Cephei::QL::Termstructures::IYieldTermStructure^ t) ;
        property Double Spread 
        {
		    virtual Double get () ;
        }
        property Cephei::QL::Instruments::IVanillaSwap^ Swap 
        {
		    virtual Cephei::QL::Instruments::IVanillaSwap^ get () ;
        }
    };
	//////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
	// Factory class
	public ref class CSwapRateHelper_Factory : public System::MarshalByRefObject,  public ISwapRateHelper_Factory
	{
	public:
        virtual ISwapRateHelper^ Create (Double rate, Cephei::QL::Indexes::ISwapIndex^ swapIndex, Microsoft::FSharp::Core::FSharpOption<Cephei::QL::IQuote^>^ spread, Microsoft::FSharp::Core::FSharpOption<Cephei::QL::Times::IPeriod^>^ fwdStart, Microsoft::FSharp::Core::FSharpOption<Cephei::QL::Termstructures::IYieldTermStructure^>^ discountingCurve);
        virtual ISwapRateHelper^ Create (Double rate, Cephei::QL::Times::IPeriod^ tenor, Cephei::QL::Times::ICalendar^ calendar, QL::Times::FrequencyEnum fixedFrequency, QL::Times::BusinessDayConventionEnum fixedConvention, Cephei::QL::Times::IDayCounter^ fixedDayCount, Cephei::QL::Indexes::IIborIndex^ iborIndex, Microsoft::FSharp::Core::FSharpOption<Cephei::QL::IQuote^>^ spread, Microsoft::FSharp::Core::FSharpOption<Cephei::QL::Times::IPeriod^>^ fwdStart, Microsoft::FSharp::Core::FSharpOption<Cephei::QL::Termstructures::IYieldTermStructure^>^ discountingCurve);
        virtual ISwapRateHelper^ Create (Cephei::QL::IQuote^ rate, Cephei::QL::Times::IPeriod^ tenor, Cephei::QL::Times::ICalendar^ calendar, QL::Times::FrequencyEnum fixedFrequency, QL::Times::BusinessDayConventionEnum fixedConvention, Cephei::QL::Times::IDayCounter^ fixedDayCount, Cephei::QL::Indexes::IIborIndex^ iborIndex, Microsoft::FSharp::Core::FSharpOption<Cephei::QL::IQuote^>^ spread, Microsoft::FSharp::Core::FSharpOption<Cephei::QL::Times::IPeriod^>^ fwdStart, Microsoft::FSharp::Core::FSharpOption<Cephei::QL::Termstructures::IYieldTermStructure^>^ discountingCurve);
        virtual ISwapRateHelper^ Create (Cephei::QL::IQuote^ rate, Cephei::QL::Indexes::ISwapIndex^ swapIndex, Microsoft::FSharp::Core::FSharpOption<Cephei::QL::IQuote^>^ spread, Microsoft::FSharp::Core::FSharpOption<Cephei::QL::Times::IPeriod^>^ fwdStart, Microsoft::FSharp::Core::FSharpOption<Cephei::QL::Termstructures::IYieldTermStructure^>^ discountingCurve);
    };
   
/*Cephei*/ } /*QL*/ } /*Termstructures*/ } /*Yield */}
